package com.xx.bili.controller;

import java.util.List;

import com.xx.bili.domain.BiLiAccount;
import com.xx.bili.service.IBiLiAccountService;
import com.xx.common.core.domain.entity.SysUser;
import com.xx.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xx.common.annotation.Log;
import com.xx.common.core.controller.BaseController;
import com.xx.common.core.domain.AjaxResult;
import com.xx.common.enums.BusinessType;
import com.xx.account.domain.AccountBoss;
import com.xx.account.service.IAccountBossService;
import com.xx.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 哔哩账号Controller
 *
 * @author ruoyi
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/bili/account")
public class BiLiAccountController extends BaseController
{
    @Autowired
    private IBiLiAccountService biLiAccountService;

    /**
     * 查询bili账户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BiLiAccount biLiAccount)
    {
        startPage();
        List<BiLiAccount> list = biLiAccountService.selectBiLiAccountList(biLiAccount);
        return getDataTable(list);
    }

    /**
     * 获取哔哩账号
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(biLiAccountService.selectBiLiAccountById(id));
    }

    /**
     * 新增哔哩账号
     */
    @PostMapping
    public AjaxResult add(@RequestBody BiLiAccount biLiAccount)
    {
        return toAjax(biLiAccountService.insertBiLiAccount(biLiAccount));
    }

    /**
     * 修改哔哩账号
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BiLiAccount biLiAccount)
    {
        return toAjax(biLiAccountService.updateBiLiAccount(biLiAccount));
    }

    /**
     * 删除哔哩账号
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(biLiAccountService.deleteBiLiAccountByIds(ids));
    }

    /**
     * 查询哔哩账号在线状态
     */
    @GetMapping("/checkBiLiAccount")
    public AjaxResult checkBiLiAccount()
    {
        return success(biLiAccountService.checkBiLiAccount());
    }

    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<BiLiAccount> util = new ExcelUtil<BiLiAccount>(BiLiAccount.class);
        util.importTemplateExcel(response, "用户数据");
    }

    /**
     * 导入用户数据
     */
    @PostMapping("/importBiLiAccount")
    public AjaxResult importBiLiAccount(MultipartFile file)
    {
        return success(biLiAccountService.importBiLiAccount(file));
    }
}
